package com.fin.zw.intelligentbot.service;

import com.fin.zw.intelligentbot.entity.DialTaskImportRecord;
import com.fin.zw.intelligentbot.entity.QDialTaskImportRecord;
import com.fin.zw.intelligentbot.repository.DialTaskImportRecordRepository;
import com.querydsl.core.BooleanBuilder;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

/**
 * @Auther:
 * @Description:
 * @Date: 2020/3/30 10:13
 */
@Service
public class DialTaskImportRecordService {

    @Autowired
    private DialTaskImportRecordRepository importRecordRepository;

    public DialTaskImportRecord save(DialTaskImportRecord record) {
        return importRecordRepository.save(record);
    }

    public Page<DialTaskImportRecord> fetchPage(DialTaskImportRecord request, Pageable pageable) {
        BooleanBuilder builder = new BooleanBuilder();
        QDialTaskImportRecord dialTaskImportRecord = QDialTaskImportRecord.dialTaskImportRecord;
        if (StringUtils.isNotBlank(request.getTaskName())) {
            builder.and(dialTaskImportRecord.taskName.like("%".concat(request.getTaskName()).concat("%")));
        }
        Page<DialTaskImportRecord> dialTaskImportRecords = importRecordRepository.findAll(builder, pageable);
        return dialTaskImportRecords;
    }
}
